<template>
     <!-- 回访记录 -->
        <div class="modal fade" id="revisitrecord" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">回访记录</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="changedocform" v-on:submit.prevent="revisitrecordsave">
                            <div class="memberinfo">
                                <p>患者姓名：<span>{{revisitrecorddata.personName}}</span></p>
                                <p>年龄：<span>{{revisitrecorddata.personAge}}岁</span></p>
                                <p>性别：<span>{{revisitrecorddata.personSexText}}</span></p>
                                <div>病种：<span>{{revisitrecorddata.chronicText}}</span></div>
                                <div>回访日期：<span>{{revisitrecorddata.hfdate}}</span></div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">回访方式：</label>
                                <div class="col-md-8">
                                    <select class="form-control" v-model="revisitrecorddata.revisitType" required>
                                        <option v-for="item in  revisitTypelist" :value="item.key">{{item.text}}</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">回访电话：</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" name="" v-model="revisitrecorddata.phoneNo" disabled>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">回访最佳时段：</label>
                                <div class="col-md-3">
                                    <input type="text" class="form-control" name="" v-model="revisitrecorddata.revisitBeginTime" required>
                                </div>
                                <div class="col-md-1">
                                    <p>-</p>
                                </div>
                                <div class="col-md-3">
                                    <input type="text" class="form-control" name="" v-model="revisitrecorddata.revisitEndTime" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">回访记录：</label>
                                <div class="col-md-8">
                                    <textarea class="form-control" v-model="revisitrecorddata.revisitRecord" required></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">下次访问日期：</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" v-model="revisitrecorddata.revisitDate" id="nextrevisitDate">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label"></label>
                                <div class="col-md-7">
                                    <button type="submit" class="default ok center">保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
</template>
<script>
import 'assets/lib/bootstrap-3.3.2/css/bootstrap.min.css'
import 'assets/lib/bootstrap-3.3.2/js/bootstrap.min.js'
import 'assets/reset.css'
import Public from 'assets/public.js'
export default {
    data() {
            return {
               revisitTypelist:[],
                //回访记录开始
                revisitrecorddata: {
                    "planId": "",
                    "mpiId": "",
                    "cycleType": "",
                    "revisitType": "",
                    "revisitBeginTime": "9:00",
                    "revisitEndTime": "17:00",
                    "remark": "",
                    "revisitRecord": "", //回访记录
                    "revisitDate": "",
                    "chronicText": "",
                    "personName": "",
                    "personAge": "",
                    personSexText: "",
                    "hfdate": "", //当前时间

                }
                //回访记录结束
            }
        },
        computed: {

        },
        components: {

        },
        props: {

        },
        ready() {
            var that=this;
                  // 获取字典
            $.when(Public.commonajax("coms.multipleDictionaryService", "findDic", "[['coms.dictionary.coms_revisitType']]"))
                .done(function(data) {
                    var data = data.body;
                   that.revisitTypelist= data[0].items

                })
        },
        methods: {
            // 验证hh:mm的方法
            validhhmm(value){
                var reg =/^(?:2[0-3]|[01]?[0-9]):[0-5][0-9]$/g;
                return reg.test(value)
            },
            //回访记录弹框
                revisitrecordmodel(mpiId) {
                    var that=this;
                    $("#revisitrecord").modal('show');
                    $.when(Public.commonajax("coms.revisitService", "findRevisitPlan", "['" + mpiId + "']"))
                        .done(function(res) {
                            if (res.code == 200) {
                                var temtextarr = [];
                                $.each(res.body.chronicList, function(index, el) {
                                    temtextarr.push(el.chronicText);
                                });
                                var temtex = temtextarr.join("、");
                                res.body.revisitDate = res.body.revisitDate.substring(0, 10);
                                res.body.chronicText = temtex;
                                res.body.hfdate = Public.formatDate();
                                res.body.revisitRecord = "";
                                res.body.revisitDate =that.getNextMonth(res.body.hfdate);
                                that.revisitrecorddata = res.body;
                            }

                        })
                },
                //回访记录保存
                revisitrecordsave() {
                    var that=this;
                    var validBeginvalue= this.validhhmm(this.revisitrecorddata.revisitBeginTime);
                     var validEndvalue= this.validhhmm(this.revisitrecorddata.revisitEndTime)

                    if(validBeginvalue&&validEndvalue){
                       $.when(Public.commonajax("coms.revisitService", "saveRevisit", "[" + JSON.stringify(this.revisitrecorddata) + "]"))
                        .done(function(res) {
                            if (res.code == 200) {
                                Public.ajaxPrompt("保存成功");
                                $("#revisitrecord").modal('hide');
                                that.$dispatch('revisitrecordsave')
                            }
                        })
                    }else{
                        Public.ajaxPrompt("请输入正确的时间格式");
                    }
                      
                },
                // 获取下一个月
                getNextMonth(date) {
                    var arr = date.split('-');
                    var year = arr[0]; //获取当前日期的年份
                    var month = arr[1]; //获取当前日期的月份
                    var day = arr[2]; //获取当前日期的日
                    var days = new Date(year, month, 0);
                    days = days.getDate(); //获取当前日期中的月的天数
                    var year2 = year;
                    var month2 = parseInt(month) + 1;
                    if (month2 == 13) {
                        year2 = parseInt(year2) + 1;
                        month2 = 1;
                    }
                    var day2 = day;
                    var days2 = new Date(year2, month2, 0);
                    days2 = days2.getDate();
                    if (day2 > days2) {
                        day2 = days2;
                    }
                    if (month2 < 10) {
                        month2 = '0' + month2;
                    }

                    var t2 = year2 + '-' + month2 + '-' + day2;
                    return t2;
                }

        },
        events: {

        },
        watch: {

        }
}
</script>
<style scoped>
    .memberinfo {
    padding: 0 20px 20px;
    bottom-border: 1px dotted #ccc
}

.memberinfo p {
    line-height: 34px;
    height: 34px;
    float: left;
    width: 33.33%;
}

.memberinfo span {
    color: #A9A9A9
}

.memberinfo>div {
    clear: both;
    line-height: 34px;
    height: 34px;
    padding-top: 10px;
}
</style>
